package com.dikang.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dikang.yygh.common.result.Result;
import com.dikang.yygh.model.user.UserInfo;
import com.dikang.yygh.user.service.UserInfoService;
import com.dikang.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    // 用户分页列表
    @GetMapping("/{page}/{limit}")
    public Result getUserInfoPage(@PathVariable("page")
                                          Long page, @PathVariable("limit") Long limit,
                                  UserInfoQueryVo userInfoQueryVo) {

        Page<UserInfo> infoPage = new Page<>();
        IPage<UserInfo> listIPage = userInfoService.selectPage(infoPage, userInfoQueryVo);
        return Result.ok(listIPage);
    }
    @ApiOperation(value = "锁定")
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable("userId") Long userId ,
                       @PathVariable("status") Integer status){
        userInfoService.lock(userId,status);
        return Result.ok();

    }
    @GetMapping("show/{userId}")
    public Result<Map<String,Object>> show(@PathVariable("userId") Long userId){
        Map<String,Object> detail = userInfoService.show(userId);
        return Result.ok(detail);
    }
    // 认证审批
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId,
                           @PathVariable Integer authStatus){
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }

}
